﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

using BitBox.Framework.Util;
using BitBox.Framework.KBR.DAL;
using BitBox.Framework.KBR.Model;

/// <summary>
/// Summary description for WS_User
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class WS_User : System.Web.Services.WebService {

    public WS_User ()
    {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [WebMethod]
    public String SelectAll()
    {
        try
        {
            UserDAL dal = new UserDAL();
            return Serializacao<List<UserInfo>>.ToXML(dal.SelectByAnyFilters(new UserInfo()));
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message.ToString(), ex);
        }
    }

    [WebMethod]
    public String SelectByAnyFilters(String ListParameters)
    {
        try
        {
            UserInfo info = new UserInfo();
            UserDAL dal = new UserDAL();
            info = Serializacao<UserInfo>.FromXML(ListParameters);

            return Serializacao<List<UserInfo>>.ToXML(dal.SelectByAnyFilters(info));
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message.ToString(), ex);
        }
    }

    [WebMethod]
    public int Insert(String ListParameters)
    {
        try
        {
            UserInfo info = new UserInfo();
            UserDAL dal = new UserDAL();
            info = Serializacao<UserInfo>.FromXML(ListParameters);

            return dal.Insert(info);
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message.ToString(), ex);
        }
    }

    [WebMethod]
    public void Update(String ListParameters)
    {
        try
        {
            UserInfo info = new UserInfo();
            UserDAL dal = new UserDAL();
            info = Serializacao<UserInfo>.FromXML(ListParameters);

            dal.Update(info);
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message.ToString(), ex);
        }
    }

    [WebMethod]
    public void Delete(int UserID)
    {
        try
        {
            UserDAL dal = new UserDAL();
            dal.Delete(UserID);
        }
        catch (Exception ex)
        {
            throw new Exception(ex.Message.ToString(), ex);
        }
    }
}
